<!DOCTYPE html>
<html>
<head>
    <title>deferred.resolve()方法和deferred.reject()方法</title>
    <meta charset="utf-8"/>
    <script src="../../../js/jquery-1.10.1.min.js"></script>
    <script>
//        var dtd = $.Deferred(); // 新建一个deferred对象
//        var wait = function(dtd){
//            var tasks = function(){
//                  alert("执行完毕!");
//                  dtd.resolve(); //改变deferred对象的执行状态
//            };
//            setTimeout(tasks, 4000);
//            return dtd;
//        };
//        $.when(wait(dtd)).done(function(){ alert("哈哈，成功了！"); }).fail(function(){ alert("出错啦！"); });


        var dtd = $.Deferred(); // 新建一个deferred对象
        var wait = function(dtd){
            var tasks = function(){
                alert("执行完毕!");
                dtd.resolve(); //改变deferred对象的执行状态
            };
            setTimeout(tasks, 3000);
            return dtd;
        };

        $.when(wait(dtd)).done(function(){ alert("哈哈，成功了！"); }).fail(function(){ alert("出错啦！"); });
        dtd.resolve();

    </script>
</head>
<body>
    <p>deferred.resolve()方法和deferred.reject()方法
        <input type="button" value="Test"/>
    </p>
</body>
</html>